<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/Timo1"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<body>
<div class="layui-card">
    <div class="layui-card-body">
<!--        <div class="text-right" style="margin-bottom: 10px;">-->
<!--            <button data-table-id="NoticeTable" class="layui-btn layui-btn-primary  layui-btn-sm"  th:data-modal="'/system/user/form?type=' + ${type} + '&companyId=' + ${companyId}" data-height="720px" data-width="800px">-->
<!--                <i class=" layui-icon layui-icon-addition"></i>创建账户</button>-->
<!--        </div>-->
        <div class="layui-card-table layui-tab">

            <div class="layui-tab-content">
                <form th:replace="/system/user/index_search">

                </form>
                <table id="UserTable" data-url="/system/user/index" data-target-search="form.form-search"></table>
            </div>
        </div>





        <script th:inline="javascript">
            var type = [[${type}]]
            var companyId  = [[${companyId}]]
        </script>

        <script type="text/javascript" th:inline="none">

            $(function () {
                let cols = [[
                    {field: 'username', title: '登录账号', minWidth: 180, align: 'center'},
                    {field: 'nickname', title: '账号名称', align: 'center'},
                    {field: 'type', title: '账号类型', align: 'center',templet: function(d){
                            if(d.type==1){
                                return '护士长';
                            }else if(d.type==2){
                                return '护理公司';
                            }else if(d.type==0){
                                return '医院管理员';
                            }else if(d.type==-1){
                                return '未设置'
                            }
                        }},
                    {toolbar: '#toolbar', title: '操作', align: 'center', minWidth: 50, fixed: 'right'}
                ]];
                if(type==1){
                    cols = [[
                        {field: 'username', title: '登录账号', minWidth: 180, align: 'center'},
                        {field: 'nickname', title: '账号名称', align: 'center'},
                        {field: 'type', title: '账号类型', align: 'center',templet: function(d){
                                if(d.type==1){
                                    return '护士长';
                                }else if(d.type==2){
                                    return '护理公司';
                                }else if(d.type==0){
                                    return '医院管理员';
                                }else if(d.type==-1){
                                    return '未设置'
                                }
                            }},
                        {field: 'depName', title: '所属科室', align: 'center'},
                        {toolbar: '#toolbar', title: '操作', align: 'center', minWidth: 50, fixed: 'right'}
                    ]];
                }
                $('#UserTable').layTable({
                    even: true, height: 'full',
                    where: {
                        type: type,
                        companyId: companyId
                    },
                    cols: cols
                });
            });

            // 数据状态切换操作
            layui.form.on('switch(StatusSwitch)', function (obj) {
                console.log("OBJ", obj)
                var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
                $.form.load("/system/user/state", data, 'post', function (ret) {
                    if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                        $('#UserTable').trigger('reload');
                    }); else {
                        $('#UserTable').trigger('reload')
                    }
                    return false;
                }, false);
            });

        </script>

        <!-- 数据状态切换模板 -->
        <script type="text/html" id="StatusSwitchTpl">
            <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已激活|已禁用" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
            <!--                    {{-d.status ? '<b class="color-green">已启用</b>' : '<b class="color-red">已禁用</b>'}}-->
        </script>

        <script type="text/html" id="toolbar">
            <a class="layui-btn layui-btn-sm" data-event-dbclick data-title="编辑用户" data-height="600px" data-modal='/system/user/form?id={{d.id}}&type={{d.type}}&companyId={{d.companyId}}' shiro:hasPermission="system:user:form">编 辑</a>
            <a class="layui-btn layui-btn-sm layui-btn-normal" th:if="${type=='2'}" data-title="设置密码" data-height="420px" data-width="460px" data-modal='/system/user/pwd?id={{d.id}}' shiro:hasPermission="system:user:pwd">密 码</a>
            <a class="layui-btn layui-btn-sm layui-btn-danger" data-event-dbclick data-confirm="确定要删除吗?"   data-action='/system/user/state?id={{d.id}}&status=3'>删除</a>
        </script>

    </div>
</div>

</body>
</html>